package com.person.title.action;

import java.util.List;

import com.person.commons.struts2.BaseAction;
import com.person.sys.model.SysMenu;
import com.person.sys.service.SysMenuService;
import com.person.title.model.TitleClass;
import com.person.title.service.TitleClassService;

public class TitleClassAction extends BaseAction {

	private TitleClassService titleClassService ;
	private SysMenuService sysMenuService ;
	private SysMenu sysMenu ;
	private List <SysMenu> sysMenus ;
	private TitleClass titleClass ;
	private List titleClasses ;
	private List titleFuncs ;
	private String classCode ;
	private String className ;
	
	private int flag = 0 ;
	
	
	/**
	 * 栏目管理的首页
	 * 左边显示所有的一级栏目
	 * 右边是栏目管理的说明
	 * @return
	 */
	public String index () {		
		return "index" ;		
	}
	
	public String left () {
		
		titleClasses = this.titleClassService.titleClassList() ;
		
		return "left" ;
	}
	
	
	public String right () {
		
		return "right" ;
	}
	
	
	/**
	 * 转向添加页面
	 * @return 
	 */
	public String preCreate () {
			
		sysMenus = sysMenuService.sysMenuList() ;
		
		return "createClass" ;
	}
	
	
	/**
	 * 添加一级功能节点
	 * @return
	 */
	public String create () {
		
		String forward = "" ;
		char state = this.titleClassService.createTitleClass(titleClass) ;
		
		if(state == '1'){
			info = getText("class.create.success");	
			flag = 1 ;
			forward = "create_success";
		}else if(state == '2'){
			
			sysMenus = sysMenuService.sysMenuList() ;
			info = getText("class.code");
			forward = INPUT;
			
		}else if(state == '3'){
			
			sysMenus = sysMenuService.sysMenuList() ;
			info =  getText("class.name");
			forward = INPUT;
		}
		
		return forward;		
	}
	
	
	/**
	 * 转向修改页面
	 * @return 
	 */
	public String preModify () {
		
		sysMenus = sysMenuService.sysMenuList() ;
	    
		titleClass = this.titleClassService.findSysClassId(titleClass.getClassId()) ;
		
		return "modifyClass" ;	
	}
	
	
	/**
	 * 修改一级功能节点
	 * @return
	 */
	public String modify(){
				
		String forward = "" ;	
		
		char state = this.titleClassService.modifyTitleClass(titleClass) ;
		char state1 = this.titleClassService.modifyJuniorTitleFunc(titleClass, classCode) ;
		
		if(state == '1' && state1=='1'){
			info = getText("class.modify.success");	
			flag = 1 ;
			forward = "modify_success";
		}else if(state == '2'){
			
			sysMenus = sysMenuService.sysMenuList() ;
			info = getText("class.code");
			forward = INPUT;
			
		}else if(state == '3'){
			
			sysMenus = sysMenuService.sysMenuList() ;
			info =  getText("class.name");
			forward = INPUT;
		}
		
		return forward;
	}
	
	
	
	/**
	 * 删除一级功能节点
	 * 
	 * @return
	 */
	public String delete() {
		String forward = "" ;
		
		if(titleClass != null) {
			titleClass = this.titleClassService.findSysClassId(titleClass.getClassId()) ;
			System.out.println (titleClass.getClassName()) ;
			char state = this.titleClassService.deleteTitleClass(titleClass) ;
			if(state == '1') {
				info = getText("class.delete.success") ;
				flag = 1;
				forward = "delete_success" ;
			}else if(state == '0') {				
				info = getText("class.delete.fail");
				forward = "delete_success";
				
			}
		}
		return forward;
	}
	
	
	/**
	 * 管理一级节点下的子功能节点
	 * @return
	 */
	public String manageFunc() { 
				
		titleClass = this.titleClassService.findSysClassId(titleClass.getClassId()) ;
		titleFuncs = this.titleClassService.juniorTitleFuncList(titleClass.getClassId()) ;
		classCode = titleClass.getClassCode() ;
		className = titleClass.getClassName() ;
		
		return "manageFunc" ;
	}
	
	
	public TitleClassService getTitleClassService() {
		return titleClassService;
	}

	public void setTitleClassService(TitleClassService titleClassService) {
		this.titleClassService = titleClassService;
	}

	public TitleClass getTitleClass() {
		return titleClass;
	}

	public void setTitleClass(TitleClass titleClass) {
		this.titleClass = titleClass;
	}

	public List getTitleClasses() {
		return titleClasses;
	}

	public void setTitleClasses(List titleClasses) {
		this.titleClasses = titleClasses;
	}

	public List getTitleFuncs() {
		return titleFuncs;
	}

	public void setTitleFuncs(List titleFuncs) {
		this.titleFuncs = titleFuncs;
	}

	public int getFlag() {
		return flag;
	}

	public void setFlag(int flag) {
		this.flag = flag;
	}

	public String getClassCode() {
		return classCode;
	}

	public void setClassCode(String classCode) {
		this.classCode = classCode;
	}



	public SysMenuService getSysMenuService() {
		return sysMenuService;
	}

	public void setSysMenuService(SysMenuService sysMenuService) {
		this.sysMenuService = sysMenuService;
	}

	public SysMenu getSysMenu() {
		return sysMenu;
	}

	public void setSysMenu(SysMenu sysMenu) {
		this.sysMenu = sysMenu;
	}

	public List<SysMenu> getSysMenus() {
		return sysMenus;
	}

	public void setSysMenus(List<SysMenu> sysMenus) {
		this.sysMenus = sysMenus;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	} 
	
	
	
	
}
